package com.itic.mall.system.orders.orderJDProject.service;

import com.itic.appbase.framework.common.service.CrudService;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.system.inter.orders.orderJDProject.persistence.dao.OrdersJDProductDao;
import com.itic.mall.system.inter.orders.orderJDProject.persistence.model.OrdersJDProduct;
import com.itic.mall.system.inter.orders.orderJDProject.persistence.model.OrdersJDProductExample;
import com.itic.mall.system.inter.orders.orderJDProject.persistence.model.OrdersJDProductExample.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class OrdersJDProductService
     extends CrudService<OrdersJDProductDao,OrdersJDProduct,OrdersJDProductExample> {
	
    @Autowired
    private OrdersJDProductDao ordersJDProductDao;
    
    
    public OrdersJDProduct getOrdersJDProjectByOrdersJDId(String orderJDId) {
    	OrdersJDProductExample example = new OrdersJDProductExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderIdEqualTo(orderJDId);
    	List<OrdersJDProduct> ordersJDProducts = this.list(example);
    	if(ordersJDProducts.isEmpty())
    		return null;
    	return ordersJDProducts.get(0);
    }
    
    /**
     * 根据订单ID和sku查订单项信息
     * @param orderJDId
     * @param skuNum
     * @return
     */
    public OrdersJDProduct getOrdersJDItem(String orderJDId,String skuNum){
    	OrdersJDProduct ordersJDProduct = null;
    	if(StringHelper.isNotBlank(orderJDId) && StringHelper.isNotBlank(skuNum)){
    		OrdersJDProductExample example = new OrdersJDProductExample();
        	Criteria criteria = example.createCriteria();
        	criteria.andOrderIdEqualTo(orderJDId);
        	criteria.andSkuIdEqualTo(skuNum);
        	List<OrdersJDProduct> ordersJDProducts = this.list(example);
        	if(ordersJDProducts.size()>0){
        		ordersJDProduct = ordersJDProducts.get(0);
        	}
    	}
    	return ordersJDProduct;
    }
    
    /**
     * 根据OrderJDId查询所有OrderJDProduct
     * @param orderJDId
     * @return
     */
    public List<OrdersJDProduct>  getOrdersJdProduct(String orderJDId) {
    	OrdersJDProductExample example = new OrdersJDProductExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderIdEqualTo(orderJDId);
    	List<OrdersJDProduct> ordersJDProducts = this.list(example);
    	return ordersJDProducts;
    }
}